package generator.service.impl;

import com.atkt.ktkt.model.vod.VideoVisitor;
import com.atkt.ktkt.vo.vod.VideoVisitorCountVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import generator.service.VideoVisitorService;
import generator.mapper.VideoVisitorMapper;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author 罗雅文
 * @description 针对表【video_visitor(视频来访者记录表)】的数据库操作Service实现
 * @createDate 2022-09-21 08:55:06
 */
@Service
public class VideoVisitorServiceImpl extends ServiceImpl<VideoVisitorMapper, VideoVisitor>
        implements VideoVisitorService {

    //课程统计的接口
    @Override
    public Map<String, Object> findCount(Long courseId, String startDate, String endData) {
        //调用mapper的方法
        List<VideoVisitorCountVo> videoVisitorVoList = baseMapper.findCount(courseId, startDate, endData);
        Map<String, Object> map = new HashMap<>();

        //创建 两个List集合 一个代表所有日期  一个代表日期对应数量
        //封装
        List<String> dateList = videoVisitorVoList.stream().map(VideoVisitorCountVo::getJoinTime).collect(Collectors.toList());
        List<Integer> countList = videoVisitorVoList.stream().map(VideoVisitorCountVo::getUserCount).collect(Collectors.toList());



        map.put("xData",dateList);
        map.put("yData",countList);

        return map;
    }
}




